package com.situ.day6;

import java.util.ArrayList;
import java.util.Scanner;

public class StudentManager {
	// main
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		ArrayList<Student> list = new ArrayList<>();
		// 输入学生信息
		while (true) {
			System.out.println("请输入学生id：");
			int id = scanner.nextInt();
			System.out.println("请输入学生姓名：");
			String name = scanner.next();
			System.out.println("请输入学生年龄：");
			int age = scanner.nextInt();
			System.out.println("请输入学生班级:");
			String className = scanner.next();
			Student student = new Student(id, name, age, className);
			list.add(student);
			
			System.out.println("是否继续添加学生？0退出");
			int reuslt = scanner.nextInt();
			if (reuslt == 0) {
				break;
			}
		}
		// 打印学生信息
		for (Student student : list) {
			System.out.println(student);
		}
		// 根据条件搜索学生信息
		// for (;;) {}
		while (true) {
			System.out.println("----------------");
			System.out.println("根据id查找： 1");
			System.out.println("根据名字查找：   2");
			System.out.println("根据年龄查找：   3");
			System.out.println("根据班级查找：   4");
			System.out.println("推出程序：   0");
			System.out.println("----------------");
			int type = scanner.nextInt();

			if (type == 0) {
				System.out.println("退出程序");
				break;
			}

			switch (type) {
			case 1:// 根据id查找
				System.out.println("id");
				System.out.println("请输入要查找的id：");
				int id = scanner.nextInt();
				boolean isSearchByIdFind = false;// 初始认为根据id没有查找到
				for (Student student : list) {
					if (id == student.getId()) {
						System.out.println(student);
						isSearchByIdFind = true;
					}
				}
				/*
				 * if (!isSearchByIdFind) { System.out.println("没有该信息的学生"); }
				 */
				if (isSearchByIdFind == false) {
					System.out.println("没有该信息的学生");
				}
				break;
			case 2:
				System.out.println("name");
				System.out.println("请输入要查找的名字：");
				String name = scanner.next();
				// Duplicate local variable isFind
				boolean isSearchByNameFind = false;
				for (Student student : list) {
					if (name.equals(student.getName())) {
						System.out.println(student);
						isSearchByNameFind = true;
					}
				}
				if (isSearchByNameFind == false) {
					System.out.println("没有该信息的学生");
				}
				break;
			case 3:
				System.out.println("age");
				break;
			case 4:
				System.out.println("className");
				break;
			default:
				break;
			}
		}
		System.out.println("end");
	}
}
